<!--
 * @Description: 
 * @Autor: Bingo
 * @Date: 2023-02-08 11:30:19
 * @LastEditors: Bingo
 * @LastEditTime: 2023-08-11 17:03:12
-->
<template>
	<div :class="isNeedPadding ? '' : 'notPad'" class="simpleTb">
		<div :class="isNeedPadding ? 'simple-content' : ''">
			<!-- 搜索框 -->
			<div class="table-page-search-wrapper" v-if="isNeedSearch">
				<SearchForm
					ref="PageSearchForm"
					v-bind="$attrs"
					:searchTitle="searchTitle"
					:searchBtnName="searchBtnName"
					:formList="formList"
					@searchData="searchData"
					@reset="reset">
					<template v-for="Slot in ['btn1', 'btn2', 'btn3', 'btn4', 'btn5', 'btn6', 'btn7']" :slot="Slot">
						<slot :name="Slot"></slot>
					</template>

					<template v-for="Slot in formList" :slot="Slot.slot" slot-scope="{ scope }">
						<slot :name="Slot.slot" :scope="scope"></slot>
					</template>
				</SearchForm>
			</div>
			<!-- 统一操作 -->
			<MainHeader v-if="isNeedMainHeade">
				<template slot="left">
					<slot name="mainHeaderLeft" :selectedRowKeys="selectedRowKeys" :selectedRow="selectedRow">
						<span class="left-logo" v-if="logoName">{{ logoName }}</span>
						<span class="left-tips" v-if="tips">{{ tips }}</span>
					</slot>
				</template>
				<!-- slot-scope 是从上一个父组件获得的数据 -->
				<template slot="right">
					<div class="table-top-button">
						<slot name="mainHeader" :selectedRowKeys="selectedRowKeys"></slot>
						<ActionBtn v-if="exportApi" title="后台下载" :loading="exportLoading" isConfirm @action="exportExcel" />
					</div>
				</template>
			</MainHeader>
			<!-- table -->
			<a-table
				:row-key="(record) => (rowKey ? record[rowKey] : record.id || record._id)"
				bordered
				@change="handleTableChange"
				:data-source="showDataList"
				:customRow="isNeedRowClick ? customRow : null"
				:pagination="isNeedPagination ? Pagination : false"
				:loading="isNeedLoading ? loading : false"
				:columns="columnList"
				:row-selection="
					isNeedRowSelect
						? {
								selectedRowKeys: selectedRowKeys,
								onChange: onSelectChange,
								type: tableType,
								onSelectAll: isNeedVirtual ? onSelectAll : null
						  }
						: null
				"
				v-bind="$attrs"
				:components="components"
				v-on="$listeners">
				<template v-for="Slot in scopedSlotsList" :slot="Slot" slot-scope="text, record, index">
					<slot :name="Slot" :text="text" :record="record" :index="index"></slot>
				</template>
			</a-table>
		</div>
		<SaveMd ref="SaveMd" @saveName="handleSaveName" />
		<MoreListMd ref="MoreListMd" :code="CODE" @setUseCol="handleSetUseCol" />
	</div>
</template>
<script>
import moment from 'moment';
import { MainHeader, ActionBtn } from '@/components';
import { uuid } from '@/utils/util';
import SearchForm from '../SearchForm';
import SimpleTbmx from '../../mixins/simpleTbmx';
import ColSet from './components/colmun';
import SaveMd from './components/saveMd';
import MoreListMd from './components/moreListMd';
import { findAllByCode, savaAndCover, batchDelete } from '@/api/tableSet';
let formatTime = (text) => text && moment(text).format('YYYY-MM-DD HH:mm:ss');
let allSeletRowKeys = [];
let allSeletRows = [];
export default {
	name: 'SimpleTb',
	props: {
		// 表格字段
		columns: {
			required: true,
			type: Array,
			default: () => {
				return [];
			}
		},
		// 搜索字段
		formList: {
			type: Array
		},
		searchTitle: {
			type: String
		},
		searchBtnName: {
			type: String
		},
		// 本地数据
		localTbData: {
			type: Array,
			default: () => {
				return [];
			}
		},
		// 数据查询接口
		apiWay: {
			type: Function
		},
		// 后台下载接口
		exportApi: {
			type: Function
		},
		// AOP查询参数切片
		apiParamsAop: {
			type: Function
		},
		// AOP返回数据分页切片函数  return {totalElements, number, size}
		apiPagination: {
			type: Function
		},
		// 是否需要选择行
		isNeedRowSelect: {
			type: Boolean,
			default: false
		},
		// table行是单选还是多选
		tableType: {
			type: String,
			default: 'checkbox'
		},
		// 用于设置个性表格
		tableId: {
			type: String | Number
		},
		// table行是单选还是多选
		dataKey: {
			type: String,
			default: 'content'
		},
		// 指定的rowkey  如果没有就默认是id
		rowKey: {
			type: String
		},
		// 是否需要序号
		isNeedNumb: {
			type: Boolean,
			default: true
		},
		// 是否需要loading
		isNeedLoading: {
			type: Boolean,
			default: true
		},
		// 是否需要序号固定
		isNeedKeyFixed: {
			type: Boolean,
			default: true
		},
		// 是否立即获取table数据  仅在无搜索表单情况下
		isNeedGetDataOnTime: {
			type: Boolean,
			default: false
		},
		// 是否需要加padding
		isNeedPadding: {
			type: Boolean,
			default: true
		},
		// 是否需要公共操作
		isNeedMainHeade: {
			type: Boolean,
			default: true
		},
		// 是否需要分页
		isNeedPagination: {
			type: Boolean,
			default: true
		},
		// 是否需要增加公共操作左侧标题
		logoName: {
			type: String
		},
		// 是否需要增加左侧提示
		tips: {
			type: String
		},
		// 是否需要行点击
		isNeedRowClick: {
			type: Boolean,
			default: true
		},
		// 是否需要个性化删减和排序表格字段
		isNeedSetTable: {
			type: Boolean,
			default: false
		},
		isNotNeedKeepLive: {
			type: Boolean,
			default: true
		},
		// 个性化分页配置对象
		paginationConfig: {
			type: Object,
			default: () => {
				return {
					pageSizeOptions: ['10', '20', '50', '100', '500', '800']
				};
			}
		},
		// 这里是为了配合将gcc和scc的原生table都改成公共组件
		// 方便在业务页面进行分页操作  需要配合paginationConfig
		isAdapterGccOrscc: {
			type: Boolean,
			default: false
		},
		// 成功后的回调
		successCallBack: {
			type: Function
		},
		// 是否取消掉只有1页的时候隐藏页签的功能
		isNeedSinglePage: {
			type: Boolean,
			default: true
		},
		// 是否需要个性化列宽拖动   注意：这里需要设置了width 才能拖动
		isNeedreSizeCellW: {
			type: Boolean,
			default: true
		},
		// 是否本地假分页
		isLocalDataPagination: {
			type: Boolean,
			default: false
		},
		// 是否开启虚拟列表功能
		isNeedVirtual: {
			type: Boolean,
			default: false
		},
		// 虚拟列表滚动配置
		VirtualConfig: {
			type: Object,
			default: () => {
				return {
					// 容器总高度
					containerHeight: 800,
					// 每行高度
					rowHeight: 41
				};
			}
		}
	},
	mixins: [SimpleTbmx],
	components: {
		SearchForm,
		MainHeader,
		ActionBtn,
		SaveMd,
		MoreListMd
	},
	computed: {
		// 插槽数组
		scopedSlotsList() {
			return this.columns.filter((item) => item.scopedSlots && item.scopedSlots.customRender).map((item) => item.scopedSlots.customRender);
		},
		// 是否需要搜索表单
		isNeedSearch() {
			return this.formList && Array.isArray(this.formList);
		},
		// 是否不需请求接口
		isLocalData() {
			return this.localTbData && Array.isArray(this.localTbData);
		},
		// 分页配置加强
		Pagination() {
			return {
				hideOnSinglePage: this.isNeedSinglePage,
				...this.pagination,
				...this.paginationConfig
			};
		},
		// 个性化设置表格的唯一code
		CODE() {
			return this.tableId ? this.$route.path + '/' + this.tableId : this.$route.path;
		},
		/* 虚拟列表逻辑 start */
		// 取数结束下标
		endIndex() {
			// 增加底部缓冲区
			let hunchongqu = Math.floor(this.containerSize / 3);
			return this.startIndex + this.containerSize + hunchongqu;
		},
		// 虚拟列表中真正展示的数据
		showDataList() {
			if (this.isNeedVirtual) {
				let startIndex = this.startIndex;
				let end = this.tableData[this.endIndex] ? this.endIndex : this.tableData.length - 1;
				// 增加缓冲区条数
				return this.tableData.slice(startIndex > this.topHcNumb ? startIndex - this.topHcNumb : startIndex, end);
			} else {
				return this.tableData;
			}
		},
		// 顶部留白高度
		topHeight() {
			let startIndex = this.startIndex;
			// 减去缓冲区高度
			if (startIndex > this.topHcNumb) {
				startIndex = startIndex - this.topHcNumb;
			}
			return startIndex * this.VirtualConfig.rowHeight + 'px';
		},
		// 顶部预留数
		topHcNumb() {
			let numb = this.startIndex;
			// 向下滚到大于6行后 只保留6条缓冲数据 否则滚动多少条就缓存多少条
			return numb > 6 ? 6 : numb;
		},
		// 可见高度下最大可见行数
		containerSize() {
			return Math.floor(this.VirtualConfig.containerHeight / this.VirtualConfig.rowHeight) + 2;
		},
		allHeight() {
			return this.tableData.length * this.VirtualConfig.rowHeight;
		}
		/* 虚拟列表逻辑 end */
	},
	watch: {
		columns() {
			this.setColumnList();
		},
		// 第一次不会执行 当isNotNeedKeepLive为true是会重新获取数据
		isNotNeedKeepLive(val) {
			if (val) {
				this.searchData({});
			}
		}
	},
	mounted() {
		// isNeedGetDataOnTime立即搜索开关
		this.isNeedGetDataOnTime && this.searchData({});
		this.isNeedSetTable && this.getAllColumnsSetData();
		this.setColumnList();
	},
	data() {
		// 增加列宽拖动能力
		this.components = {
			header: {
				cell: (h, props, children) => {
					const { key, ...restProps } = props;
					const col = this.columnList.find((col) => {
						const k = col.dataIndex || col.key;
						return k === key;
					});

					if (!this.isNeedreSizeCellW || !col || !col.width) {
						return h('th', { ...restProps }, [...children]);
					}
					// 传给drag组件的props  注意 dataSelfIndex 是为了防止有些字段可能跟antd or drag组件的Key有重复 可单独设置不一的值
					const dragProps = {
						key: col.dataSelfIndex || col.dataIndex || col.key,
						class: 'table-draggable-handle',
						attrs: {
							w: 10,
							x: col.width,
							z: 1,
							axis: 'x',
							draggable: true,
							resizable: true
						},
						on: {
							dragging: (x, y) => {
								col.width = Math.max(x, 1);
							}
						},
						draggable: true,
						resizable: true
					};
					const drag = h('vue-draggable-resizable', { ...dragProps });
					return h('th', { ...restProps, class: 'resize-table-th' }, [...children, drag]);
				}
			}
		};

		return {
			requestDataIng: false,
			startIndex: 0,
			// 原始表单字段
			columnList: [],
			// 选中的字段
			checkColumnList: [],
			// 保存后的字段
			newColumnList: [],
			// 已经设置过的个性化字段列表
			hasSetColumnList: [],
			filterDropdownVisible: false,
			currentSetTitle: '',
			totalElements: 0
		};
	},
	methods: {
		/* 虚拟列表相关 */
		// 计算底部撑起高度
		calBottomHeight() {
			return (this.totalElements - this.endIndex) * this.VirtualConfig.rowHeight + 'px';
		},
		// 获取虚拟列表基本dom并填充上下空白撑起滚动条
		// 添加滚动监听事件
		handleVirtual() {
			this.patchHandleDom('ant-table-body', true);
			// 这里加定时器的原因是 a-table左边fixed的时候会比右边慢渲染 为了保证能获取到dom
			setTimeout(() => {
				this.patchHandleDom('ant-table-body-inner', true);
			}, 300);
		},
		// 滚动事件 动态改变取数开始和结束下标
		handleVirtualScroll() {
			requestAnimationFrame(() => {
				let tbDom = document.getElementsByClassName('ant-table-body')[0];
				// 滚动条滚动的距离与每行高度比值就是最新取数开始下标
				let currentIndex = ~~(tbDom.scrollTop / this.VirtualConfig.rowHeight);
				// 只在需要变化的时 才重新赋值
				let isCanScroll = this.startIndex !== currentIndex;
				if (isCanScroll) {
					this.startIndex = currentIndex;
				}
				// 判断是否到达指定底部
				this.handleLoadMore(tbDom.scrollTop);
				this.handleTopBottomPadding(tbDom.scrollTop, isCanScroll);
			});
		},
		// 这里为了兼容分页处理  到底后加载新数据
		handleLoadMore() {
			if (this.startIndex + this.containerSize > this.tableData.length - 1) {
				// 判断是否还有更多的数据
				let haveMoreData = this.totalElements != this.tableData.length;
				if (!this.requestDataIng && haveMoreData) {
					this.parameter = { ...this.parameter, pageIndex: this.parameter.pageIndex + 1 };
					this.fetchList(this.parameter);
					this.requestDataIng = true;
				}
			}
		},
		// 动态改变上下撑起padding的大小 使得可见列表始终在可见范围
		handleTopBottomPadding(isCanScroll) {
			this.patchHandleDom('ant-table-body', false, isCanScroll);
			this.patchHandleDom('ant-table-body-inner', false, isCanScroll);
		},
		// 这里用循环的原因是  可能存在左右固定的现象 要确保所有的容器都处理到 防止滚动会上下跳动的现象
		patchHandleDom(className, needAddEvent = true, isCanScroll) {
			let tbDom = document.getElementsByClassName(className);
			if (!tbDom) return;
			let allPaddingTob = this.allHeight - this.containerSize * this.VirtualConfig.rowHeight;
			let topHeight = this.topHeight;
			let bottomHeight = this.calBottomHeight();
			for (let i = 0; i < tbDom.length; i++) {
				if (tbDom[i]) {
					tbDom[i].firstChild.style.paddingTop = isCanScroll ? topHeight : allPaddingTob;
					tbDom[i].firstChild.style.paddingBottom = isCanScroll ? bottomHeight : 0;
					needAddEvent && tbDom[i].addEventListener('scroll', this.handleVirtualScroll, false);
				}
			}
		},
		// 全选处理
		onSelectAll(selected) {
			// 全选
			if (selected) {
				if (!allSeletRowKeys.length) {
					let keys = this.rowKey ? this.rowKey : 'id';
					allSeletRowKeys = this.tableData.map((item) => item[keys]);
					this.selectedRowKeys = [...allSeletRowKeys];
					this.selectedRow = allSeletRows = [...this.tableData];
				} else {
					this.selectedRowKeys = [...allSeletRowKeys];
					this.selectedRow = [...allSeletRows];
				}
			}
			// 取消全选
			if (!selected) {
				this.selectedRowKeys = allSeletRowKeys = [];
				this.selectedRow = allSeletRows = [];
			}
		},
		// 处理排序操作
		handleSorter(firection, sortKey) {
			let data = JSON.parse(JSON.stringify(this.tableData));
			// 降序
			if (firection == 'descend') {
				data.sort((a, b) => b[sortKey] - a[sortKey]);
			} else if (firection == 'ascend') {
				data.sort((a, b) => a[sortKey] - b[sortKey]);
			}
			this.tableData = [...data];
		},
		// ------------个性化表格设置 start-----------------
		setTable() {
			this.$refs.KkModal.show();
		},
		/*
			item:{
				isTime 是否为时间字段 boolean
				isSorter  是否需要排序 string 可以是S/T/N
				UnEllipsis 是否需要省略并加工具提示框 boolean
			}
		*/
		setColumnList(colList) {
			let res = this.formatColumnList(colList);
			this.columnList = res;
			this.setCheckColumnList(res);
		},
		//   统一处理排序问题 分为时间、字符串、数字 T/S/N
		formatColumnList(colList) {
			let columnList = colList || this.columns;
			if (!columnList.length) return;
			let res = columnList.map((item) => {
				if (item.isTime) {
					item.customRender = formatTime;
				}
				if (item.isSorter) {
					item = {
						...item,
						sorter: (a, b) => {
							if (item.isSorter === 'T') {
								return moment(a[item.dataIndex]) - moment(b[item.dataIndex]);
							} else if (item.isSorter === 'S') {
								return a[item.dataIndex].length - b[item.dataIndex].length;
							} else if (item.isSorter === 'N') {
								return a[item.dataIndex] - b[item.dataIndex];
							}
						},
						sortField: item.dataIndex
					};
				}
				if (item.ellipsis === undefined) {
					item.ellipsis = true;
				}
				// TODO 可以考虑传字典进来渲染  UnEllipsis为true则增加tool提示
				if (!item.UnEllipsis) {
					// 这里不能统一设置 因为它的优先级会大于业务页面的插槽 那么字典转换会失效
				} else {
					item.customRender = (text, record, index) => {
						return {
							children: (
								<a-tooltip>
									<template slot="title">{text}</template>
									{text}
								</a-tooltip>
							)
						};
					};
				}
				return item;
			});
			// 自动填充序号列
			if (this.isNeedNumb && !colList) {
				res.unshift(
					this.isNeedSetTable
						? {
								filterDropdownVisible: this.filterDropdownVisible,
								...this.rebackComCode()
						  }
						: {
								...this.unNeedSortComCode()
						  }
				);
			}

			return res;
		},
		onFilterDropdown() {
			this.filterDropdownVisible = !this.filterDropdownVisible;
			this.retsetNumb();
		},
		retsetNumb() {
			this.columnList.splice(
				0,
				1,
				this.isNeedSetTable
					? {
							filterDropdownVisible: this.filterDropdownVisible,
							...this.rebackComCode()
					  }
					: {
							...this.unNeedSortComCode()
					  }
			);
		},
		// 获取所有的个性化设置数据
		async getAllColumnsSetData() {
			try {
				let res = await findAllByCode({
					code: this.CODE
				});
				this.hasSetColumnList = res;
				// 找出默认设置的列表
				this.handleDefaultColumn(res);
			} catch (e) {}
		},

		// 找出默认设置的列表
		handleDefaultColumn(res) {
			if (res.length == 0) return;
			let currentUseColumn = res.filter((item) => item.isDefault);
			let setContent = JSON.parse(currentUseColumn[0].setContent);

			if (setContent.length == 0) return;
			// 判断是否字段列表被更改过
			if (this.handleJudgedHasChange(setContent)) {
				let ids = res.map((item) => item.id);
				this.$message.warn('当前列表字段有更新,已删除原有设置!');
				batchDelete(ids);
				this.setColumnList();
				return;
			}
			this.currentSetTitle = currentUseColumn[0].title;
			this.checkColumnList = setContent;
			let newarr = setContent.filter((item) => item.checked);
			newarr.unshift(
				this.isNeedSetTable
					? {
							filterDropdownVisible: this.filterDropdownVisible,
							...this.rebackComCode()
					  }
					: {
							...this.unNeedSortComCode()
					  }
			);

			this.columnList = newarr;
		},
		handleJudgedHasChange(setContent) {
			let colNameList = [];
			this.columnList.forEach((item) => {
				if (item.title != '序号') {
					colNameList.push(item.dataIndex);
				}
			});
			const isTimeOut = setContent.some((item) => {
				return colNameList.indexOf(item.dataIndex) < 0;
			});
			return isTimeOut;
		},
		// 将所有字段都置为选中
		setCheckColumnList(columnList) {
			let data = [];
			columnList.forEach((item) => {
				data.push({ checked: true, ...item });
			});
			this.checkColumnList = data;
		},
		handleSetUseCol(record) {
			this.currentSetTitle = record.title;
			this.submitData(JSON.parse(record.setContent));
			this.checkColumnList = JSON.parse(record.setContent);
		},
		// 点击确定后重置显示
		submitData(ColumnList) {
			let newarr = ColumnList.filter((item) => item.checked);
			newarr.unshift(
				this.isNeedSetTable
					? {
							filterDropdownVisible: this.filterDropdownVisible,
							...this.rebackComCode()
					  }
					: {
							...this.unNeedSortComCode()
					  }
			);
			this.setColumnList(newarr);
		},
		// 查看更多个性字段设置
		async lookMore() {
			if (this.$refs.MoreListMd.visible) {
				this.$refs.MoreListMd.close();
			} else {
				try {
					this.$refs.MoreListMd.confirmLoading = true;
					let res = await findAllByCode({
						code: this.CODE
					});
					this.$refs.MoreListMd.confirmLoading = false;
					this.$refs.MoreListMd.show(res);
				} catch (e) {
					this.$refs.MoreListMd.confirmLoading = false;
				}
			}
		},
		colSetComSubmit(colList) {
			let newarr = colList.filter((item) => item.checked);
			newarr.unshift(
				this.isNeedSetTable
					? {
							filterDropdownVisible: this.filterDropdownVisible,
							...this.rebackComCode()
					  }
					: {
							...this.unNeedSortComCode()
					  }
			);

			this.columnList = this.formatColumnList(newarr);
		},
		// 需要进行排序和筛选的
		rebackComCode() {
			return {
				dataIndex: 'numb',
				width: 65,
				title: '序号',
				fixed: this.isNeedKeyFixed ? 'left' : null,
				filterIcon: () => <a-icon type="setting" theme="filled" />,
				filterDropdown: () => (
					<ColSet
						ref="ColSet"
						currentSetTitle={this.currentSetTitle}
						checkColumnList={this.checkColumnList}
						onLookMore={this.lookMore}
						onSubmitData={this.colSetComSubmit}
						onHandleSaveCol={this.handleSaveCol}
					/>
				),
				onFilterDropdownVisibleChange: this.onFilterDropdown,
				customRender: (text, record, index) => {
					let children = null;
					if (this.isNeedVirtual) {
						children = <span>{record.numb}</span>;
					} else {
						if (this.isAdapterGccOrscc) {
							children = <span>{(this.paginationConfig.current - 1) * this.paginationConfig.pageSize + index + 1}</span>;
						} else {
							children = (
								<span>
									{this.isNeedPagination ? (this.Pagination.current - 1) * this.Pagination.pageSize + index + 1 : index + 1}
								</span>
							);
						}
					}

					return {
						children
					};
				}
			};
		},
		unNeedSortComCode() {
			return {
				dataIndex: 'numb',
				width: 70,
				title: '序号',
				fixed: this.isNeedKeyFixed ? 'left' : null,
				customRender: (text, record, index) => {
					let children = null;
					if (this.isNeedVirtual) {
						children = <span>{record.numb}</span>;
					} else {
						if (this.isAdapterGccOrscc) {
							children = <span>{(this.paginationConfig.current - 1) * this.paginationConfig.pageSize + index + 1}</span>;
						} else {
							children = (
								<span>
									{this.isNeedPagination ? (this.Pagination.current - 1) * this.Pagination.pageSize + index + 1 : index + 1}
								</span>
							);
						}
					}
					return {
						children
					};
				}
			};
		},
		// 打开保存弹框
		handleSaveCol(newColmunList) {
			this.newColumnList = newColmunList;
			this.$refs.SaveMd.show();
		},
		// 保存个性化数据
		handleSaveName(name) {
			let data = {
				title: name,
				code: this.CODE,
				setContent: JSON.stringify(this.newColumnList)
			};
			this.$refs.SaveMd.confirmLoading = true;
			savaAndCover(data)
				.then(() => {
					this.$message.success('保存成功');
					this.$refs.SaveMd.closeMd();
				})
				.catch((err) => {
					this.$refs.SaveMd.confirmLoading = false;
				});
			this.checkColumnList = JSON.parse(JSON.stringify(this.newColumnList));
		},
		// ------------个性化表格设置 end-----------------
		// 行点击操作
		customRow(record) {
			return {
				on: {
					click: () => {
						let keys = this.rowKey ? record[this.rowKey] : record.id || record._id;
						if (this.tableType === 'radio') {
							this.selectedRowKeys = [keys];
							this.selectedRow = [record];
						} else {
							let rowKeys = this.selectedRowKeys;
							let rowDatas = this.selectedRow;
							if (rowKeys.length > 0 && rowKeys.includes(keys)) {
								rowKeys.splice(rowKeys.indexOf(keys), 1);
								rowDatas = rowDatas.filter((item) => {
									let _res = this.rowKey ? item[this.rowKey] : item.id || item._id;
									return _res != keys;
								});
							} else {
								rowKeys.push(keys);
								rowDatas.push(record);
							}
							this.selectedRowKeys = rowKeys;
							this.selectedRow = rowDatas;
						}
					}
				}
			};
		},
		// 搜索查询  二次直接调用即可
		searchData(params) {
			this.parameter = this.handleObject(this.parameter, params);
			this.fetchList(this.parameter);
		},
		handleObject(parameter, params = {}) {
			let obj = { pageSize: this.Pagination.pageSize, betweenMap: {}, searchMap: {}, sortArr: [], dto: {}, ...params };
			Object.keys(obj).forEach((item) => {
				if (parameter.hasOwnProperty(item)) {
					obj[item] = params[item] || parameter[item];
				}
			});
			obj.pageIndex = 1;
			return obj;
		},
		// 数据查询
		fetchList(parameter) {
			// 远程接口数据
			if (typeof this.apiWay == 'function') {
				if (this.apiParamsAop && typeof this.apiParamsAop == 'function') {
					parameter = this.apiParamsAop(parameter);
					this.parameter = { ...parameter };
				}
				if (!parameter) return; // 校验，通过apiParamsAop给parameter赋值为false以阻断列表请求
				this.loading = true;
				this.apiWay(parameter).then(
					(res) => {
						if (res && res[this.dataKey] instanceof Array) {
							this.requestDataIng = false;
							this.totalElements = res.totalElements;
							// this.tableData = res[this.dataKey];
							// 虚拟列表特殊处理 序号
							if (this.isNeedVirtual) {
								// 这里不需要分页
								if (!this.isLocalDataPagination) {
									this.tableData = res[this.dataKey].map((item, index) => {
										return {
											...item,
											numb: this.isNeedPagination
												? (this.Pagination.current - 1) * this.Pagination.pageSize + index + 1
												: index + 1
										};
									});
								} else {
									// 这里需要分页
									this.tableData = [
										...this.tableData,
										...res[this.dataKey].map((item, index) => {
											return {
												...item,
												numb: (this.parameter.pageIndex - 1) * this.parameter.pageSize + index + 1
											};
										})
									];
								}
								// 开启虚拟列表逻辑
								this.handleVirtual();
							} else {
								this.tableData = res[this.dataKey];
							}
							if (this.apiPagination && typeof this.apiPagination == 'function') {
								let { totalElements, number, size } = this.apiPagination(res);
								this.pagination.total = totalElements;
								this.$page.setPageByfetchData(this.pagination, totalElements, number, size);
							} else {
								this.pagination.total = res.totalElements;
								this.$page.setPageByfetchData(this.pagination, res.totalElements, res.number, res.size);
							}

							if (this.successCallBack && typeof this.successCallBack == 'function') {
								this.successCallBack(this.tableData);
							}
						} else {
							this.$notification['error']({
								message: '数据获取失败或格式有误',
								description: ''
							});
						}
						this.loading = false;
						this.selectedRowKeys = [];
						this.selectedRow = [];
					},
					(err) => {
						this.loading = false;
						this.selectedRowKeys = [];
						this.selectedRow = [];
					}
				);
				// 本地数据分页
			} else {
				this.pagination.total = this.tableData.length;
				if (this.isNeedVirtual) {
					this.tableData = (this.localTbData || []).map((item, index) => {
						return {
							...item,
							numb: this.isNeedPagination ? (this.Pagination.current - 1) * this.Pagination.pageSize + index + 1 : index + 1
						};
					});
					this.handleVirtual();
				} else {
					this.tableData = this.localTbData || [];
				}
			}
		},
		// 分页等操作
		handleTableChange(e, key, sorter) {
			// 需要调接口 同时 非本地分页的情况
			if (typeof this.apiWay == 'function' && !this.isLocalDataPagination) {
				sorter?.order &&
					(this.parameter.sortArr = [
						{
							direction: sorter.order === 'descend' ? 'DESC' : 'ASC',
							filed: sorter.columnKey
						}
					]);
				this.$page.handlePageChange(e, key, this.parameter, this.fetchList);
			} else {
				if (this.isNeedPagination) {
					this.pagination.current = e.current;
				}
				// 本地排序处理
				this.handleSorter(sorter.order, sorter.columnKey);
			}
		},
		async exportExcel() {
			if (typeof this.exportApi == 'function') {
				try {
					this.$message.loading({ content: '后台下载中...', key: 'ADD', duration: 0 });
					this.exportLoading = true;
					const queryData = { ...this.parameter };
					const res = await this.exportApi(queryData);
					this.$message.success({ content: res.detail || '后台下载成功，请到下载中心查看结果！', key: 'ADD', duration: 2 });
					this.exportLoading = false;
				} catch (e) {
					this.$message.destroy();
					this.exportLoading = false;
				}
			} else {
				this.$message.success({ content: '下载失败', key: 'ADD', duration: 2 });
			}
		},
		// 选择操作
		onSelectChange(selectedRowKeys, selectedRow) {
			this.selectedRowKeys = selectedRowKeys;
			this.selectedRow = selectedRow;
			this.$emit('onTableSelectChange', { selectedRowKeys, selectedRow });
		},
		clearSearchData() {
			this.$refs.PageSearchForm.simpleResetForm();
			this.parameter = {
				betweenMap: {},
				searchMap: {},
				sortArr: [],
				dto: {},
				pageIndex: 1,
				pageSize: 10
			};
			setTimeout(() => this.$refs.PageSearchForm.queryData(), 300);
		},
		reset() {
			this.parameter = {
				betweenMap: {},
				searchMap: {},
				sortArr: [],
				dto: {},
				pageIndex: 1,
				pageSize: 10
			};
			this.$emit('reset');
		}
	}
};
</script>
<style scoped lang="less"></style>
<style lang="less">
.table-draggable-header-com() {
	height: 100% !important;
	left: auto !important;
	right: -5px;
	touch-action: none;
	border: none;
	position: absolute;
	transform: none !important;
	bottom: 0;
}
.table-draggable-handle {
	.table-draggable-header-com();
	cursor: col-resize;
}
.table-draggable-forbidden {
	.table-draggable-header-com();
}
.resize-table-th {
	position: relative;
}

.left-logo {
	position: relative;
	font-weight: 700;
	color: #000;
	padding-left: 13px;

	&::before {
		content: '';
		position: absolute;
		left: 0;
		top: 2px;
		width: 5px;
		height: 15px;
		border-radius: 8px;
		background: linear-gradient(180deg, #367ff9, #ffffff);
	}
}

.notPad {
	.ant-card-body {
		padding: 0 !important;
	}
}

.simple-content {
	padding: 0 24px 24px;
}
.cantMove {
	cursor: not-allowed;
}
.ant-table-fixed-left table,
.ant-table-fixed-right table {
	width: min-content;
}
.simpleTb {
	.ant-table-filter-icon {
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
.btnarr-right {
	display: flex;
	flex-direction: row;
	align-items: center;
	.export-btn {
		margin-left: 8px;
	}
}
.left-tips {
	color: red;
}
</style>
